<?php
/***********************************************************************************************
        File Name                :        class_page.inc
        File Description        :        contains variables, functions dealing with the page layout
        Include Files        :        class_pgsql.inc
        Created By        :        S.Gnanavel
        Created On        :        14 March 2003
        Modified By        :        R.Lakshmi Narayanan
        Modified On        :        21 March 2003
***********************************************************************************************/

class cPage
        {
        // declaration starts here
        var $title;
        var $heading="";
        var $header_path="";
        var $user_menu_path="../";
        var $master_menu_path="../";
        var $sub_menu_path="../";
        var $footer_path="../";
        var $master_menu="";
        var $sub_menu="";
        var $logo=false;
        var $stylesheet = "general/stylesheet1.css";
        var $print_stylesheet="general/stylesheet_print.css";
        // end of declaration

        function cPage()
                {
                $this->title="Welcome to Payir";
                }

        /*****************************************************************************************
         Function Name         :doHeaderHtml
         No. of Arguments        :Nil
         Arguments                :Nil
         Action                        :starts the page layout as a table, sets the stylesheet and
                                                 displays the company logo in the first row and opens
                                                the next row with the first column
         Returns                        :Nil
         Created By                :S.Gnanavel
         Created On                :14 March 2003
         Modified By                :R.Lakshmi Narayanan
         Modified On                :21 March 2003
        *****************************************************************************************/
        function doHeaderHtml()
                {
		/* 
		 * Gets the Browser Information 
		 */ 
		$browser = $_SESSION["browser_identify"];
		/* 
		 * If Browser is Mozila Family gets the theme from the session 
		 * For Other Browsers it will loads the other_browser theme
		 */
		if($browser=='moz')
			{
			$stylesheet = $_SESSION["guser_preferences"]["theme"];
			}
		else
			{
			$stylesheet = "other_browser.css";
			}
		require_once("xajax/xajax.inc.php");
		$xajax = new xajax();
                ?>
                <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                <html>
                <head>
			<LINK REL="Address Icon" HREF="<?php echo $this->header_path;?>images/bsg_logo.jpg">
                        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                        <title><?php echo $this->title; ?></title>
                        <link rel="stylesheet" type="text/css" href="<?php echo $this->header_path;echo $this->stylesheet?>" />
			<link rel="stylesheet" href="<?php echo $this->header_path;?>general/<?php echo $stylesheet;?>.css">
			<!-- 	For Calendar Display 	 -->
			<script type="text/javascript" src="<?php echo $this->header_path;?>jscripts/epoch_classes.js"></script>
			<link rel="stylesheet" type="text/css" href="<?php echo $this->header_path;?>general/epoch_styles.css" />
			<div id="ms_cal"></div>
			<!-- 			 -->
			<?
			$xajax->printJavascript($this->header_path."includes/xajax/");
			?>
                </head>
		<?
		echo "<body onload=\"getFocus();writeMenu('$this->header_path','$_SESSION[guser_type_id]');defaultRow();showCalendar();\">";
		?>
                <!-- When window is resized reload the page for automatic adjustment of menu-->
                <!--<script language="JavaScript" src="<?php echo $this->header_path;?>menu/reload.js"></script>-->
                <!-- menu script itself. you should not modify this file -->
                
                <script language="JavaScript" src="<?php echo $this->header_path;?>date_picker/date-picker.js"></script>
		<script language="JavaScript" src="<?php echo $this->header_path;?>date_picker/javascript.js"></script>
		<script language="JavaScript" src="<?php echo $this->header_path;?>jscripts/finished_leather_production_javascript.js"></script>
		<script language="JavaScript" src="<?php echo $this->header_path;?>jscripts/calculator.js"></script>
                <!-- items structure. menu hierarchy and links are stored there -->
                <!-- files with geometry and styles structures -->
                <?php
                if($_SESSION["gmember_id"] > 1000 && $_SESSION["gmember_id"] != 100002)
			{
			if($_SESSION["guser_preferences"]["language"])
				{
				$lang="_".substr($_SESSION["guser_preferences"]["language"],0,2);
				}
			else
				{
				$lang="_en";	
				}
			$user_type_id = $_SESSION["guser_type_id"];
			$menu_file="menu/menu"."_"."$user_type_id"."$lang".".js";
			?>
			<link href="<?php echo $this->header_path;?>menu/menu1.css" rel="stylesheet" type="text/css"/>
			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
			<script type="text/javascript" src="<?php echo $this->header_path.$menu_file;?>"></script>
			<div class="dynamic_menu" id="dynamic_menu" style="top:200px;"></div>
                        <?php 
                        }
                ?>
                <table width="100%" align="left" cellpadding="0" cellspacing="0">
                        <tbody>
                                <tr>
                                <td colspan="4" align="center" >
                                <?php
                                if($logo)
					{
					$image=$this->header_path."images/logo.gif"?>
					<a href="<?php echo $this->header_path; echo "users/redirect.php";?>">
					<img src="<?php echo $image?>" border="0" alt="<?php echo $this->LABEL["global_html.inc"]["Company_Name"]?>" title="<?php echo $this->LABEL["global_html.inc"]["Home_Page"]?>">
					<?php
					}
                                else
                                	{
					$company_id=$_SESSION["gmember_id"];
					if ($_SESSION["gprivilege"][$company_id])
                                                {
						?>
						<div style="background:#ffffff;border:1px solid;position:relative;width:108%;height:30px;left:-39px;top:-5px;">
						<?}?>
                                        <table align="left" cellspacing="0" cellpadding="0" padding="0" margin="0" >
					<tr>
                                        <td align="center" width="950px" >
                                        <?php
                                        echo "<h1>விவசாயப் பயிர்த் திட்டம்</h1>";
					
					?>
                                        </td>
                                        <td align="right" width="500px" style="padding-bottom:10px;">
                                        </td>
					</tr>
                                        </table>
					</div>
                                        <?php
                                }?>
                                </td>
                                </tr>
                <!-- Javascript to set focus to the first non -hidden element of a form-->
                <SCRIPT LANGUAGE="JavaScript">
                <!--
                function getFocus()
                        {
                        var form_name=document.forms[1];
                        // If form is there in a page
                        if(form_name)
                                {
                                for(i=0;i<form_name.elements.length;i++)
                                        {
                                        if (form_name.elements[i].type != "hidden")
                                                {
                                                form_name.elements[i].focus();
                                                return 1;
                                                }
                                        }
                                }
                        }
                -->
                </SCRIPT>
                <?php
                }        // end of function doHeaderHtml


        /*****************************************************************************************
         Function Name         :doCentreHtml
         No. of Arguments        :Nil
         Arguments                :Nil
         Action                        :closes the first column of the second row and starts a new
                                                 column and displays the heading in the center.  If
                                                sub menu is given displays it next to the heading on the
                                                right hand side using the user defined function doSubMenu
         Returns                        :Nil
         Created By                :S.Gnanavel
         Created On                :14 March 2003
         Modified By                :R.Lakshmi Narayanan
         Modified On                :21 March 2003
        *****************************************************************************************/
        function doCentreHtml()                // function starts here
                {
                if($_SESSION["gfarmer_id"])
                        {
                        ?>
                        </td>
                        <td width="96%" valign="top">
			<a href="farmer-details.php"> உங்கள் விபரங்கள்</a> | <a href="payir-entry.php"> பயிர் விபரம் உள்ளிடல்</a> | <a href="logout.php"> வெளியேற </a>                        
			<!-- displays the heading -->
                        <div align="right">வாங்க <?php echo $_SESSION["gfarmer_name"];?></b></div>
                        <br><h4><?php echo $this->heading ?></h4>
                        <?php
                        
                        }
                else
                        {
                        ?>
                        </td>
                        <td width="2%" height="355"></td>
                        <td width="83%" valign="top">
                        <!-- displays the heading -->
                        <br><h4><?php echo $this->heading ?></h4>
                        <?php
                        }
                }        // end of function doCentreHtml


        /*****************************************************************************************
         Function Name         :doFooterHtml
         No. of Arguments        :Nil
         Arguments                :Nil
         Action                        :closes the second column and opens the next row and
                                                 displays the links to the pages dealing with the
                                                company information.
         Returns                        :Nil
         Created By                :S.Gnanavel
         Created On                :14 March 2003
         Modified By                :R.Lakshmi Narayanan
         Modified On                :21 March 2003
        *****************************************************************************************/
        function doFooterHtml()                // function starts here
                {
                //$tri1_image=$this->header_path."images/tri1.jpg";
                //$bar_image=$this->header_path."images/bar.jpg";
                ?>
                <!--End of the centre cell-->
                </td>
                <td width="2%" height="550"><td>
                </tr>
                <!--end of the page formatting table-->
                <!--print the general links within the stylesheet class defined in the stylesheet-->
                <tr align="center">
                <td colspan="3" align="center">
                <table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                <td style="border-top:1px solid;">
                உருவாக்கமும் பராமரிப்பும் : <a href="http://code.google.com/p/payir">பயிர் குழுவினர்</a>
		<?php
		global $startTime;
		list($usec, $sec) = explode(" ", microtime());
		$endTime=((float)$usec + (float)$sec);
		$time = $endTime - $startTime;
		echo number_format($time,2)." விநாடிகள் எடுத்துக் கொண்டது.\n";
		?>
                </td>
                </tr>
                </table>
                </td>
                </tbody>
                </table>
                </body>
                </html>
                <?php
                }        // end of function doFooterHtml

        /*************************************************************************************************************************************

                Function Name   : doPrintHeader

                Arguments       : title of the page ($title),
                                stylesheet name ($stylesheet)

                Action          : prints the html header for printable pages

                Returns         : Nil

                Modified on     : Sep 02, 2002

                Modified by     : Siva Kumar

        ***************************************************************************************************************************************/

        function doPrintHeader()
                {
                //HTML header
                               if($_GET["ob"]==1)
                        {
                        ob_start();
                        }
 ?>
                <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                <html>
                <head>
                        <meta http-equiv="Content-Language" content="en-us">
                        <meta http-equiv="Content-Type" content="text/html; charset=iso8859-01">
                        <title><?php echo $this->title?></title>
                        <link rel="stylesheet" type="text/css" href="<?php echo ($this->header_path); echo
$this->print_stylesheet?>">
                </head>
                <body >
                <?php
                echo "<h4 align=\"center\">$this->heading </h4>";
                }

        /*************************************************************************************************************************************

                Function Name    : doPrintFooter

                Arguments       :

                Action          : Footer for printable report

                Returns         :

                Modified on     : Sep 02, 2002

                Modified by     : R.Lakshmi Narayanan

        ***************************************************************************************************************************************/

        function doPrintFooter()
                {
                ?>

                </body>
                </html>
                <?php
                                if($_GET["ob"]==1)
                        {
                        $output_file=basename($_SERVER["PHP_SELF"],".php");
                        $pdf_file = $output_file.".pdf";
                        $html_file = $output_file.".html";
                        $fp = fopen($html_file,"w");
                        if($fp)
                                {
                                $output = ob_get_contents();
                                fwrite($fp,$output);
                                ob_end_clean();
                                echo exec('htmldoc --webpage --header ... --footer 1 --pagemode document -t pdf -f '.$pdf_file.' '.$html_file);
                                echo exec('rm '.$html_file);
                                header("Location:./".$pdf_file);
                                exit;
                                }        
                        }
		}
/********* Function to include javascripts & styles for popup window *********/
	function popupWindow()
		{
		/* 
		 * Gets the Browser Information 
		 */ 
		$browser = $_SESSION["browser_identify"];
		/* 
		 * If Browser is Mozila Family gets the theme from the session 
		 * For Other Browsers it will loads the other_browser theme
		 */
		if($browser=='moz')
			{
			$stylesheet = $_SESSION["guser_preferences"]["theme"];
			}
		else
			{
			$stylesheet = "other_browser.css";
			}
		?>
		<head>
		<title><?php echo $this->title?></title>
 		<!-- Modified by mugunthan for Theme Selection Menu -->
		<link rel="stylesheet" href="<?php echo $this->header_path;?>general/<?php echo $stylesheet;?>.css">
		<!-- Modified by Mugunthan ends here -->
		<script language="JavaScript">
		var gRowId=1;
		function defaultRow(){} //Don't remove this
		</script>
		<script language="JavaScript" src="<?php echo $this->header_path;?>jscripts/finished_leather_production_javascript.js"></script>
		</head>
		<body onload="defaultRow();">
		<h4><?php echo $this->heading ?></h4>
		<?
		}
        }

/*****************************************************************************************
Function Name         :returnLink
No. of Arguments        :3
Arguments                :$link - file to be displayed along with the path
                         $name - Display name for the link
                         $query_string_array - associative array of values passed as query string
Action                        :generates the html tag for displaying the link along with the query string
                                and returns it.
Returns                        :html tag for displaying a link
Created By                :S.Gnanavel
Created On                :14 March 2003
Modified By                :R.Lakshmi Narayanan
Modified On                :26 May 2003
*****************************************************************************************/


function returnLink($link="",$name="", $query_string_array="", $target="", $access_key="",$title="")
        {
        $url_string="<a accesskey=\"$access_key\" href=\"$link";
        if ($query_string_array)
                {
                $url_string .= "?";
                foreach ($query_string_array as $key => $value)
                        {
                        // check whether the array contains only one item or more than one items.
                        if (count($query_string_array) ==1)   //if only one item end the query
                                $url_string .= "$key=$value";
                        else   //otherwise
                                {
                                $url_string .="$key=$value"."&";
                                //  and removes the first value in the array
                                array_shift($query_string_array);
                                }
                        }
                }

        $url_string.="\" title=\"$title\"";
        $url_string.=($target)?" target=$target" : "";
	if($name == "Printable Report")
		{
		$url_string.="><img border=\"0\" title = \"Printable Report\" src=\"../../images/print.png\" name=\"b1\" /></a>";
		}
	elseif($name == "View as PDF")
		{
		$url_string.="><img border=\"0\" height=\"5px\" title = \"View as PDF\" src=\"../../images/pdf1.jpeg\" name=\"b1\" /></a>";
		}
	elseif($name == "Full Page View")
		{
		$url_string.="><img border=\"0\" height = 25px title = \"Full Page View\" src=\"../../images/viewmag.png\" name=\"b1\" /></a>";
		}
	else
		{
		$url_string.="><b>$name</b></a>";
		}
        return $url_string;
        }
?>
